@echo off
setlocal enabledelayedexpansion

if "%1"=="" (
    echo Usage:
    echo   case.bat add ^<caseNO^>    - Add case demo to build
    echo   case.bat clear           - Clear all case configurations
    echo   case.bat new ^<typeName-caseNO-desc^>    - create new case demo
    echo   case.bat buildall    - build demos hap with all cases
    echo   case.bat build ^<caseNO^>    - build demos hap with specified cases
    exit /b 1
)

if "%1"=="add" (
    if "%2"=="" (
        echo Error: caseNO is required
        echo Example: case.bat add case001
        exit /b 1
    )
    echo Adding case demo %2...
    call hvigorw caseAdd -p caseNO=%2
    call ohpm install --all --registry https://ohpm.openharmony.cn/ohpm/ --strict_ssl false
    call hvigorw --sync
    exit /b 0
)

if "%1"=="clear" (
    echo Clearing case configurations...
    call hvigorw caseClear
    call ohpm install --all --registry https://ohpm.openharmony.cn/ohpm/ --strict_ssl false
    call hvigorw --sync
    exit /b 0
)

if "%1"=="new" (
    if "%2"=="" (
        echo Error: demoname is required
        echo Example: case.bat new ArkUI-case001-test
        exit /b 1
    )
    echo new case demo %2...
    call hvigorw generateModule -p demoname=%2
    call ohpm install --all --registry https://ohpm.openharmony.cn/ohpm/ --strict_ssl false
    call hvigorw --sync
    exit /b 0
)

if "%1"=="buildall" (
    echo execute clear case demos....
    call hvigorw caseClear
    echo execute add all case demos....
    call hvigorw caseAddAll
    echo execute install hars....
    ohpm install --all --registry https://ohpm.openharmony.cn/ohpm/ --strict_ssl false
    call hvigorw --sync
    echo execute build hap....
    call hvigorw --mode module -p module=default@default -p product=default assembleHap
    exit /b 0
)

if "%1"=="build" (
    if "%2"=="" (
        echo Error: caseNO is required
        echo Example: case.bat build case001
        exit /b 1
    )
    echo execute clear case demos....
    call hvigorw caseClear
    echo execute add case demo %2...
    call hvigorw caseAdd -p caseNO=%2
    echo execute install hars....
    ohpm install --all --registry https://ohpm.openharmony.cn/ohpm/ --strict_ssl false
    call hvigorw --sync
    echo execute build hap....
    call hvigorw --mode module -p module=default@default -p product=default assembleHap
    exit /b 0
)

echo Error: Unknown command '%1'
echo Valid commands are: add, clear
exit /b 1 